<!--
 * @Description: In User Settings Edit
 * @Author: your name
 * @Date: 2019-09-06 00:34:26
 * @LastEditTime: 2019-11-11 20:09:44
 * @LastEditors: Please set LastEditors
 -->
<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>Hello APP</title>
    <link rel="stylesheet" type="text/css" href="../css/vant.css">
    <link rel="stylesheet" type="text/css" href="../css/base.css" />
    <script type="text/javascript" src="../script/jquery.js"></script>
    <script type="text/javascript" src="../script/echarts.js"></script>
    <script type="text/javascript" src="../script/layer/mobile/layer.js"></script>
    <script type="text/javascript" src="../script/vue.min.js"></script>
    <script type="text/javascript" src="../script/vant.min.js"></script>
    <script type="text/javascript" src="../script/fastclick.js"></script>
    <script type="text/javascript" src="../script/base.js"></script>
    <style type="text/css">
        .van-cell__value {
            text-align: right;
        }

        .spec {
            display: inline-block;
            color: #cd1b21;
            text-decoration: underline;
        }
    </style>
</head>

<body>
    <div id="app" v-cloak>
        <div class="init-full">
            <van-nav-bar class="head" :title="type == 1?'销售明细':'收款明细'" left-arrow @click-left="onClickLeft">
                <div slot="right" class="head-right">
                    <span @click="showSearch = true;">
                        <img src="../image/search.png" />
                    </span>
                </div>
            </van-nav-bar>
            <div class="body-with-bottom">
                <div class="content">
                    <van-list v-model="listLoading" :finished="listFinished" finished-text="没有更多了" @load="listOnLoad">
                        <div class="report" style="background: transparent;">
                            <div class="table-full">
                                <table>
                                    <tr>
                                        <th>客户</th>
                                        <th>金额</th>
                                        <th>日期</th>
                                        <th>单据名称</th>
                                        <th>单据号</th>

                                    </tr>
                                    <tr v-for="row in dataList">
                                        <td>{{row.ClientName}}</td>
                                        <td class="td_right">{{row.DMoney}}</td>
                                        <td class="td_center">{{row.BillDate}}</td>
                                        <td class="td_center">{{row.BillName}}</td>
                                        <td class="td_center" @click="intoDetail(row)"><span
                                                class="spec">{{row.BillNO}}</span></td>

                                    </tr>
                                </table>
                            </div>

                        </div>
                    </van-list>


                </div>
                <van-loading v-if="showLoading" />
            </div>
            <div class="bottom">
                <div class="bottom-left-label">
                    <span>合计金额：</span>
                    <span class="number">￥{{sumPrice}}</span>
                </div>
                <div class="bottom-right-button"></div>
            </div>
        </div>

        <van-popup v-model="showSearch" round position="bottom">
            <div>
                <van-cell title="往来单位" :value="searchData.S_CXClientName" is-link @click="openScreen(-1,10)">
                </van-cell>
            </div>
            <div class="btn-padding">
                <van-button type="primary" block style="border-radius: 0;" @click="searchList">查询</van-button>
            </div>
        </van-popup>
    </div>
</body>

<script type="text/javascript">
    var vm;
    apiready = function () {
        //$('.init-full').show();
        var userInfo = FLD.getUserInfo();

        var type = api.pageParam.type;
        var row = api.pageParam.row;

        api.setScreenOrientation({
            orientation: 'auto'
        })

        api.addEventListener({
            name: 'keyback'
        }, function (ret, err) {
            vm.onClickLeft();
        });

        api.addEventListener({
            name: 'selectArray'
        }, function (ret, err) {
            var selectType = ret.value.selectType;
            var type = ret.value.type;
            var array = ret.value.array;
            if (selectType == 10) {
                var nameArray = [];
                var idArray = [];
                for (var i in array) {
                    nameArray.push(array[i].name);
                    idArray.push(array[i].id);
                }
                vm.searchData.S_CXClientName = nameArray.join();
                vm.searchData.S_CXClientID = idArray.join() || 0;
            }
        })

        vm = new Vue({
            el: '#app',
            data: {
                showLoading: false,
                listLoading: false,
                listFinished: true,
                showSearch: false,
                searchData: {
                    S_CXClientID: 0,
                    S_CXClientName: ''
                },
                sumPrice: 0,
                type: type,
                dataList: [],
                pageIndex: 1,
                pageSize: 20,
            },
            created: function () {
                var that = this;
                that.getList();

            },
            methods: {
                getList() {
                    var that = this;
                    that.showLoading = true;
                    var obj = {
                        S_Type: row.BType,
                        S_BranchID: row.BranchID,
                        S_PeriodID: row.JS_PeriodID,
                        S_ColType: type,
                        S_RoleID: row.RoleID,
                        S_BSName: row.BSName,
                        S_Pageindex: that.pageIndex,
                        S_PageSize: that.pageSize,
                        S_CXClientID: that.searchData.S_CXClientID
                    }
                    FLD.ajax('AP_SYXQMX', obj, function (res) {
                        that.showLoading = false;
                        that.listFinished = false;
                        that.dataList = res.ds;
                        that.sumPrice = res.ds1[0].SumMoney;
                    })
                },
                listOnLoad(index) {
                    var that = this;
                    that.pageIndex++;
                    var obj = {
                        S_Type: row.BType,
                        S_BranchID: row.BranchID,
                        S_PeriodID: row.JS_PeriodID,
                        S_ColType: type,
                        S_RoleID: row.RoleID,
                        S_BSName: row.BSName,
                        S_Pageindex: that.pageIndex,
                        S_PageSize: that.pageSize,
                        S_CXClientID: that.searchData.S_CXClientID
                    }
                    FLD.ajax('AP_SYXQMX', obj, function (res) {
                        that.listLoading = false;
                        if (res.ds.length == 0) {
                            that.listFinished = true;
                        }
                        that.dataList = that.dataList.concat(res.ds);
                        that.sumPrice = res.ds1[0].SumMoney;
                    })
                },
                searchList() {
                    var that = this;
                    that.showSearch = false;

                    that.pageIndex = 1;

                    this.getList();
                },
                openScreen(type, index) {
                    var obj = {
                        S_Type: index,
                        S_Cont: '',
                        S_BranchID: this.searchData.S_BranchID,
                        S_SXZ: '',
                        S_StockID: 0,
                        S_CargoID: 0,
                        S_BarCode: '',
                        S_PriceN: 0,
                        S_ProductID: 0
                    }
                    api.openWin({
                        name: '筛选' + index,
                        url: 'common/baseMultipleScreen.html',
                        reload: true,
                        slidBackEnabled: false,
                        pageParam: {
                            filterData: obj,
                            type: type,
                            allowClear: false
                        }
                    })
                },
                intoDetail(d) {
                    var that = this;
                    var obj = {
                        S_BillType: d.BillType,
                        S_BillID: d.BillID
                    }
                    if (d.BillType == 101 || d.BillType == 1101 || d.BillType == 401) {
                        FLD.ajax('AP_HisList_XX', obj, function (res) {
                            if (res.ds.length) {
                                var row = res.ds[0];
                                if (d.BillType == 101 || d.BillType == 1101) {
                                    if (row.B_Type == 3) {
                                        api.openWin({
                                            name: 'sellingPrint',
                                            url: 'sellingPrint.html',
                                            reload: true,
                                            slidBackEnabled: false,
                                            pageParam: {
                                                historyData: row
                                            }
                                        })
                                    } else {
                                        api.openWin({
                                            name: 'selling',
                                            url: 'selling.html',
                                            reload: true,
                                            slidBackEnabled: false,
                                            pageParam: {
                                                historyData: row
                                            }
                                        })
                                    }
                                } else if (d.BillType == 401) {
                                    api.openWin({
                                        name: 'receipt',
                                        url: 'receipt.html',
                                        reload: true,
                                        slidBackEnabled: false,
                                        pageParam: {
                                            historyData: row
                                        }
                                    })
                                }
                            }
                        })
                    } else {
                        var obj = {
                            S_BillType: d.BillType,
                            S_BillID: d.BillID
                        }
                        FLD.ajax('APP_BillLinkN', obj, function (res) {
                            if (res.ds.length) {
                                api.openWin({
                                    name: 'formConfig',
                                    url: 'common/formConfig.html',
                                    reload: true,
                                    slidBackEnabled: false,
                                    pageParam: {
                                        keyName: res.ds[0].B_KeyCol,
                                        keyValue: d.BillID,
                                        objName: res.ds[0].APPListName,
                                        titleName: res.ds[0].BillName
                                        // isPosted: true
                                    }
                                })
                            }
                        })
                    }

                },
                onClickLeft() {
                    api.setScreenOrientation({
                        orientation: 'portrait_up'
                    })
                    api.closeWin();
                }
            }
        })
    };
</script>

</html>